﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using dbo;
using LitJson;
namespace MiracleIsland
{
    class Manager
    {
        private string Ip = "192.168.197.72";
        private int Port=22222;
        private Socket ss;
        private string ConnectionString = string.Format("DataSource={0};DataBase={1};UserId={2};PassWord={3}","localhost","island","tony","tohnyaz");
        public Manager() 
        {
           
            DBManager.ConnectionString = this.ConnectionString;
            test();
            ss = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
            ss.Bind(new IPEndPoint(IPAddress.Parse(Ip),Port));
            ss.Listen(100);
            new Thread(Accept).Start();
        }
        void Accept() 
        {
          while(true)
          {
              Socket cs = ss.Accept();
          }
        }
        void test() 
        {
            JsonData jd = new JsonData();
            jd.SetJsonType(JsonType.Array);
            for (int i = 0; i < 5;i++ )
            {
                JsonData boss = new JsonData();
                JsonData dt = new JsonData();
                dt.SetJsonType(JsonType.Array);
                dt.Add(1);
                dt.Add(2);
                dt.Add(3);
                boss["data"] = dt;
                jd.Add(boss);
            }
            jd[4]["data"][2] = 100;
            DBManager.Update(string.Format("update player set Head='{0}'",jd.ToJson()));
            DataRowCollection drc = DBManager.Select("select Head from player");
            JsonData _head = JsonMapper.ToObject((string)drc[0][0]);
            Console.WriteLine(_head.ToJson());
            string s = "[{'data':[1,2,3]},{'data':[1,2,3]}]";
            Console.WriteLine(JsonMapper.ToObject(s).ToJson());
        }
    }
    struct Element 
    {
        /**************************
         * 1.建筑
         * 2.动物
         * 3.道路
         * 4.土壤块（种田用的）
        *************************/



        public int Id;//元素Id
        public DateTime StartTime;//开始的时间
        public int State;//当前的状态
        public string position;//位置

    }
}
